home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / util / mactosvx / part01
Encoding:
Text File  |  1990-10-11  |  12.7 KB  |  385 lines

  1. Path: wuarchive!uunet!abcfd20.larc.nasa.gov!amiga-request
  2. From: amiga-request@abcfd20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i277: Macto8SVX 1.0 - Mac Sound to Amiga 8SVX converter, Part01/01
  5. Message-ID: <comp.sources.amiga:v90i277@abcfd20.larc.nasa.gov>
  6. Date: 11 Oct 90 01:06:11 GMT
  7. Reply-To: "Tim Friest - Programmer/Analyst"  <AXTBF%ALASKA.BITNET@CORNELLC.cit.cornell.edu>
  8. Lines: 372
  9. Approved: tadguy@uunet.UU.NET (Tad Guy)
  10. X-Mail-Submissions-To: amiga@uunet.uu.net
  11. X-Post-Discussions-To: comp.sys.amiga
  12.  
  13. Submitted-by: "Tim Friest - Programmer/Analyst"  <AXTBF%ALASKA.BITNET@CORNELLC.cit.cornell.edu>
  14. Posting-number: Volume 90, Issue 277
  15. Archive-name: util/macto8svx-1.0/part01
  16.  
  17. This is a little program I wrote to convert Mac sound samples to Amiga
  18. IFF 8SVX format...   It uses 2.0 stuff, so you'll need 2.0 to compile it.
  19.  
  20. #!/bin/sh
  21. # This is a shell archive.  Remove anything before this line, then unpack
  22. # it by saving it into a file and typing "sh file".  To overwrite existing
  23. # files, type "sh file -c".  You can also feed this as standard input via
  24. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  25. # will see the following message at the end:
  26. #        "End of archive 1 (of 1)."
  27. # Contents:  Macto8SVX.c Macto8SVX.doc
  28. # Wrapped by tadguy@abcfd20 on Wed Oct 10 21:06:09 1990
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'Macto8SVX.c' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'Macto8SVX.c'\"
  32. else
  33. echo shar: Extracting \"'Macto8SVX.c'\" \(9075 characters\)
  34. sed "s/^X//" >'Macto8SVX.c' <<'END_OF_FILE'
  35. X/*
  36. X * Read a Mac sound file and convert it to an IFF 8SVX sound file
  37. X *
  38. X * by: Tim Friest
  39. X * on: 6-August-1990
  40. X */
  41. X
  42. X#include <exec/types.h>
  43. X#include <clib/exec_protos.h>
  44. X#include <pragma/exec_pragma.h>
  45. X#include <exec/memory.h>
  46. X#include <dos/dos.h>
  47. X#include <dos/rdargs.h>
  48. X#include <clib/dos_protos.h>
  49. X#include <pragma/dos_pragma.h>
  50. X#include <libraries/iffparse.h>
  51. X#include <clib/iffparse_protos.h>
  52. X#include <pragma/iffparse_pragma.h>
  53. X#include <iff/iff.h>
  54. X#include <iff/8SVX.h>
  55. X
  56. Xextern struct library *DOSBase;
  57. X
  58. Xchar *version  = "\0$VER: MacTo8SVX 1.0 (8-Aug-90)";
  59. X#define        CREDITS "MacTo8SVX v1.0 (8-Aug-90) by Tim Friest (PD)\n"
  60. X
  61. X#define        ARG_TEMPLATE    "MacSound/A,IFF8SVX/A,Rate=SampleRate/K/N"
  62. X
  63. X#define OPT_FILENAME   0
  64. X#define        OPT_IFFNAME     1
  65. X#define        OPT_RATE        2
  66. X
  67. X#define        OPT_COUNT       3
  68. Xchar   *cmd_opts[OPT_COUNT];
  69. X
  70. Xstruct RDArgs  *argsptr;
  71. X
  72. Xextern void SignalIFFError(int);
  73. Xextern void main(void);
  74. Xvoid main() {
  75. X       int status;
  76. X       ULONG AllocFlags = 0;
  77. X       struct FileInfoBlock    *fib;
  78. X       BPTR    file, flock;
  79. X       struct library *IFFParseBase;
  80. X       struct IFFHandle *IFFHandle;
  81. X       char *filename, *iffname;
  82. X       int SampleRate;
  83. X       Voice8Header VHDR;
  84. X       UBYTE *SoundData;
  85. X       LONG SoundLen, i;
  86. X
  87. X       if ((IFFParseBase = OpenLibrary("iffparse.library", 0)) == NULL) {
  88. X               Write(Output(), "Unable to open IFFParse Library\n", 32);
  89. X               goto CleanUp;
  90. X       }
  91. X       AllocFlags |= (1<<0);
  92. X
  93. X       if ((argsptr = ReadArgs(ARG_TEMPLATE, (LONG *)cmd_opts, NULL)) == NULL)
  94. X{
  95. X               Write(Output(), "Usage: ", 7);
  96. X               Write(Output(), ARG_TEMPLATE, sizeof(ARG_TEMPLATE));
  97. X               Write(Output(), "\n", 1);
  98. X               Write(Output(), CREDITS, sizeof(CREDITS));
  99. X               goto CleanUp;
  100. X       }
  101. X       AllocFlags |= (1<<10);
  102. X
  103. X       filename = cmd_opts[OPT_FILENAME];
  104. X       iffname = cmd_opts[OPT_IFFNAME];
  105. X       if (cmd_opts[OPT_RATE])
  106. X               SampleRate = *(int *)cmd_opts[OPT_RATE];
  107. X       else
  108. X               SampleRate = 11;
  109. X
  110. X       if ((file = Open(filename, MODE_OLDFILE)) == NULL) {
  111. X               Write(Output(), "Error opening file\n", 19);
  112. X               goto CleanUp;
  113. X       }
  114. X       AllocFlags |= (1<<11);
  115. X
  116. X       if ((flock = Lock(filename, MODE_OLDFILE)) == NULL) {
  117. X               Write(Output(), "Error locking file\n", 19);
  118. X               goto CleanUp;
  119. X       }
  120. X       AllocFlags |= (1<<12);
  121. X
  122. X       if ((fib = (struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock)
  123. X, MEMF_CLEAR)) == NULL) {
  124. X               Write(Output(), "Not enough memory for file info block\n", 28);
  125. X               goto CleanUp;
  126. X       }
  127. X       AllocFlags |= (1<<13);
  128. X
  129. X       if (!Examine(flock, fib)) {
  130. X               Write(Output(), "Examine failed!\n", 16);
  131. X               goto CleanUp;
  132. X       }
  133. X       SoundLen = fib->fib_Size;
  134. X
  135. X       FreeMem((char *)fib, sizeof(struct FileInfoBlock));
  136. X       AllocFlags &= ~(1<<13);
  137. X
  138. X       UnLock(flock);
  139. X       AllocFlags &= ~(1<<12);
  140. X
  141. X       if ((SoundData = AllocMem(SoundLen, MEMF_CLEAR)) == NULL) {
  142. X               Write(Output(), "Not enough memory\n", 18);
  143. X               goto CleanUp;
  144. X       }
  145. X       AllocFlags |= (1<<14);
  146. X
  147. X       if (Read(file, SoundData, SoundLen) < SoundLen) {
  148. X               Write(Output(), "Error reading file\n", 19);
  149. X               goto CleanUp;
  150. X       }
  151. X       Close(file);
  152. X       AllocFlags &= ~(1<<11);
  153. X
  154. X       for (i=0; i < SoundLen; i++)
  155. X               SoundData[i] ^= 0x80;   /* toggle high bit */
  156. X
  157. X       VHDR.oneShotHiSamples = SoundLen;
  158. X       VHDR.repeatHiSamples = 0;
  159. X       VHDR.samplesPerHiCycle = 0;
  160. X       switch (SampleRate) {
  161. X               case 5:
  162. X                       VHDR.samplesPerSec = 5696; /*  5.564 * 1024 */
  163. X                       break;
  164. X               case 7:
  165. X                       VHDR.samplesPerSec = 7596; /*  7.418 * 1024 */
  166. X                       break;
  167. X               case 11:
  168. X                       VHDR.samplesPerSec = 11395; /* 11.128 * 1024 */
  169. X                       break;
  170. X               case 22:
  171. X                       VHDR.samplesPerSec = 22790; /* 22.256 * 1024 */
  172. X                       break;
  173. X               default:
  174. X                       Write(Output(), "Sample rate one of 5, 7, 11 and 22, usi
  175. Xng 11\n", 45);
  176. X                       VHDR.samplesPerSec = 11395;
  177. X       } /* switch */
  178. X       VHDR.ctOctave = 1;
  179. X       VHDR.sCompression = sCmpNone;
  180. X       VHDR.volume = Unity;
  181. X
  182. X       if ((IFFHandle = AllocIFF()) == NULL) {
  183. X               Write(Output(), "Not enough memory to allocate IFF Handle\n", 41
  184. X);
  185. X               goto CleanUp;
  186. X       }
  187. X       AllocFlags |= (1<<1);
  188. X       if ((IFFHandle->iff_Stream = (ULONG)Open(iffname, MODE_NEWFILE)) == NULL
  189. X) {
  190. X               Write(Output(), "Error opening file\n", 19);
  191. X               goto CleanUp;
  192. X       }
  193. X       AllocFlags |= (1<<2);
  194. X       InitIFFasDOS(IFFHandle);
  195. X
  196. X       if ((status = OpenIFF(IFFHandle, IFFF_WRITE)) != 0) {
  197. X                       SignalIFFError(status);
  198. X                       goto CleanUp;
  199. X       }
  200. X       AllocFlags |= (1<<3);
  201. X
  202. X       if ((status = PushChunk(IFFHandle, ID_8SVX, ID_FORM, IFFSIZE_UNKNOWN)) !
  203. X= 0) {
  204. X               SignalIFFError(status);
  205. X               goto CleanUp;
  206. X       }
  207. X
  208. X       if ((status = PushChunk(IFFHandle, ID_8SVX, ID_VHDR, sizeof(Voice8Header
  209. X))) != 0) {
  210. X               SignalIFFError(status);
  211. X               goto CleanUp;
  212. X       }
  213. X       if ((status = WriteChunkBytes(IFFHandle, &VHDR, sizeof(Voice8Header))) <
  214. X= 0) {
  215. X               SignalIFFError(status);
  216. X               goto CleanUp;
  217. X       }
  218. X       if ((status = PopChunk(IFFHandle)) != 0) { /* pop the 8SVX VHDR chunk */
  219. X               SignalIFFError(status);
  220. X               goto CleanUp;
  221. X       }
  222. X
  223. X       if ((status = PushChunk(IFFHandle, ID_8SVX, ID_BODY, SoundLen)) != 0) {
  224. X               SignalIFFError(status);
  225. X               goto CleanUp;
  226. X       }
  227. X       if ((status = WriteChunkBytes(IFFHandle, SoundData, SoundLen)) <= 0) {
  228. X               SignalIFFError(status);
  229. X               goto CleanUp;
  230. X       }
  231. X       if ((status = PopChunk(IFFHandle)) != 0) { /* pop the 8SVX BODY chunk */
  232. X               SignalIFFError(status);
  233. X               goto CleanUp;
  234. X       }
  235. X
  236. X       if ((status = PopChunk(IFFHandle)) != 0) { /* pop the FORM 8SVX chunk */
  237. X               SignalIFFError(status);
  238. X               goto CleanUp;
  239. X       }
  240. X
  241. X
  242. X/*
  243. X * Deallocate and close all resources used
  244. X */
  245. XCleanUp:
  246. X       if (AllocFlags & (1<<14))
  247. X               FreeMem(SoundData, SoundLen);
  248. X       if (AllocFlags & (1<<13))
  249. X               FreeMem((char *)fib, sizeof(struct FileInfoBlock));
  250. X       if (AllocFlags & (1<<12))
  251. X               Close(file);
  252. X       if (AllocFlags & (1<<11))
  253. X               UnLock(flock);
  254. X       if (AllocFlags & (1<<10))
  255. X               FreeArgs(argsptr);
  256. X       if (AllocFlags & (1<<3))
  257. X               CloseIFF(IFFHandle);
  258. X       if (AllocFlags & (1<<2))
  259. X               Close(IFFHandle->iff_Stream);
  260. X       if (AllocFlags & (1<<1))
  261. X               FreeIFF(IFFHandle);
  262. X       if (AllocFlags & (1<<0))
  263. X               CloseLibrary(IFFParseBase);
  264. X}
  265. X
  266. X/*
  267. X * Signal IFF error codes to user
  268. X */
  269. Xvoid SignalIFFError(error)
  270. Xint error;
  271. X{
  272. X       switch (error) {
  273. X               case IFFERR_EOF:
  274. X                       Write(Output(), "IFFError: Reached logical end of file\n
  275. X", 38);
  276. X                       break;
  277. X               case IFFERR_EOC:
  278. X                       Write(Output(), "IFFError: About to leave context\n", 33
  279. X);
  280. X                       break;
  281. X               case IFFERR_NOSCOPE:
  282. X                       Write(Output(), "IFFError: No valid scope for property\n
  283. X", 38);
  284. X                       break;
  285. X               case IFFERR_NOMEM:
  286. X                       Write(Output(), "IFFError: Internal memory alloc failed\
  287. Xn", 39);
  288. X                       break;
  289. X               case IFFERR_READ:
  290. X                       Write(Output(), "IFFError: Stream read error\n", 28);
  291. X                       break;
  292. X               case IFFERR_WRITE:
  293. X                       Write(Output(), "IFFError: Stream write error\n", 29);
  294. X                       break;
  295. X               case IFFERR_SEEK:
  296. X                       Write(Output(), "IFFError: Stream seek error\n", 28);
  297. X                       break;
  298. X               case IFFERR_MANGLED:
  299. X                       Write(Output(), "IFFError: Data in file is corrupt\n",34
  300. X );
  301. X                       break;
  302. X               case IFFERR_SYNTAX:
  303. X                       Write(Output(), "IFFError: IFF syntax error\n", 27);
  304. X                       break;
  305. X               case IFFERR_NOTIFF:
  306. X                       Write(Output(), "IFFError: Not an IFF file\n", 26);
  307. X                       break;
  308. X               case IFFERR_NOHOOK:
  309. X                       Write(Output(), "IFFError: No call-back hook provided\n"
  310. X, 37);
  311. X                       break;
  312. X               case IFF_RETURN2CLIENT:
  313. X                       Write(Output(), "IFFError: Client handler normal return\
  314. Xn", 39);
  315. X                       break;
  316. X               default:
  317. X                       Write(Output(), "IFFError: unknown error encountered\n",
  318. X 36);
  319. X       } /* switch (error) */
  320. X}
  321. X
  322. END_OF_FILE
  323. if test 9075 -ne `wc -c <'Macto8SVX.c'`; then
  324.     echo shar: \"'Macto8SVX.c'\" unpacked with wrong size!
  325. fi
  326. # end of 'Macto8SVX.c'
  327. fi
  328. if test -f 'Macto8SVX.doc' -a "${1}" != "-c" ; then 
  329.   echo shar: Will not clobber existing file \"'Macto8SVX.doc'\"
  330. else
  331. echo shar: Extracting \"'Macto8SVX.doc'\" \(912 characters\)
  332. sed "s/^X//" >'Macto8SVX.doc' <<'END_OF_FILE'
  333. X
  334. X
  335. X                             Mac_To_8SVX
  336. X                                 by
  337. X                             Tim Friest
  338. X                             8-Aug-1990
  339. X
  340. XMacTo8SVX is a AmigaOS 2.0 program which converts Macintosh digitized sound
  341. Xdata to an Amiga IFF 8SVX sound file.
  342. X
  343. XThe program assumes that the Mac data is simply that (a stream of bytes
  344. Xwithout a header, resource fork, or whatever).  I got the speeds for the
  345. Xsampling rates from the March/April 1990 AmigaMail article by John Orr.
  346. X
  347. XThis program only runs under AmigaOS 2.0 (I couldn't resist the IFFParse
  348. Xlibrary or the new DOS calls...  Thanks to Leo, Stuart, and C=.
  349. X
  350. XThis program is not copyrighted and may be destributed or modified in any
  351. Xway you desire.  If you make modifications, I'd appreciate credit where due.
  352. X
  353. XI can be reached:
  354. X
  355. XUSMail:        Tim Friest                      BIX: TFRIEST
  356. X       211 McCarrey #1
  357. X       Anchorage, AK 99508
  358. END_OF_FILE
  359. if test 912 -ne `wc -c <'Macto8SVX.doc'`; then
  360.     echo shar: \"'Macto8SVX.doc'\" unpacked with wrong size!
  361. fi
  362. # end of 'Macto8SVX.doc'
  363. fi
  364. echo shar: End of archive 1 \(of 1\).
  365. cp /dev/null ark1isdone
  366. MISSING=""
  367. for I in 1 ; do
  368.     if test ! -f ark${I}isdone ; then
  369.     MISSING="${MISSING} ${I}"
  370.     fi
  371. done
  372. if test "${MISSING}" = "" ; then
  373.     echo You have the archive.
  374.     rm -f ark[1-9]isdone
  375. else
  376.     echo You still need to unpack the following archives:
  377.     echo "        " ${MISSING}
  378. fi
  379. ##  End of shell archive.
  380. exit 0
  381. -- 
  382. Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
  383. Mail comments to the moderator at <amiga-request@uunet.uu.net>.
  384. Post requests for sources, and general discussion to comp.sys.amiga.
  385.